package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduCourseClassMapper;
import com.zenith.edu.po.domain.EduCourseClass;
import com.zenith.edu.po.dto.EduCourseClassDTO;
import com.zenith.edu.po.vo.EduCourseClassVO;
import com.zenith.edu.service.EduCourseClassService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduCourseClassServiceImpl extends ServiceImpl<EduCourseClassMapper, EduCourseClass> implements EduCourseClassService {
    
    @Override
    public EduCourseClassVO createCourseClass(EduCourseClassDTO dto) {
        EduCourseClass courseClass = new EduCourseClass();
        BeanUtils.copyProperties(dto, courseClass);
        this.save(courseClass);
        
        EduCourseClassVO vo = new EduCourseClassVO();
        BeanUtils.copyProperties(courseClass, vo);
        return vo;
    }
    
    @Override
    public EduCourseClassVO getCourseClassById(Long id) {
        EduCourseClass courseClass = this.getById(id);
        if (courseClass == null) {
            return null;
        }
        
        EduCourseClassVO vo = new EduCourseClassVO();
        BeanUtils.copyProperties(courseClass, vo);
        return vo;
    }
    
    @Override
    public EduCourseClassVO updateCourseClass(EduCourseClassDTO dto) {
        EduCourseClass courseClass = new EduCourseClass();
        BeanUtils.copyProperties(dto, courseClass);
        this.updateById(courseClass);
        
        EduCourseClassVO vo = new EduCourseClassVO();
        BeanUtils.copyProperties(courseClass, vo);
        return vo;
    }
    
    @Override
    public boolean deleteCourseClass(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduCourseClassVO> getCourseClassList() {
        List<EduCourseClass> courseClassList = this.list();
        return courseClassList.stream().map(courseClass -> {
            EduCourseClassVO vo = new EduCourseClassVO();
            BeanUtils.copyProperties(courseClass, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}